﻿using MDT.LifeSewagePlatform.Conmmon;
using MDT.LifeSewagePlatform.Entity;
using MDT.LifeSewagePlatform.IRepository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace MDT.LifeSewagePlatform.Repository
{
    public class RegionRepository:BaseRepository<RegionEntity>,IRegionRepository
    {
        public RegionRepository()
        {

        }

        public IQueryable<RegionView> GetRegionViews(Expression<Func<RegionView,bool>> exp)
        {
            var query = from region in _dbContext.Regions.AsNoTracking()
                        join typename in _dbContext.Details.AsNoTracking().Where(t => t.MainID == (int)eDictionaryType.Region) on region.RegionType equals typename.RowID
                        select new RegionView()
                        {
                            RegionType=region.RegionType,
                            Code=region.Code,
                            Latitude=region.Latitude, 
                            Longitude=region.Longitude,
                            Description=region.Description,
                            DisplayName=region.DisplayName,
                            Id=region.ID,
                            ParentID=region.ParentID,
                            TypeName=typename.RowName
                        };
            return query.Where(exp);
        }
    }
}
